package com.chen.Sign.common;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 陈帅彬
 * @date 2023/2/6 20:32
 */
@ControllerAdvice(annotations = {RestController.class, Controller.class})
@SuppressWarnings({"all"})
@ResponseBody
@Slf4j
public class GlobalExceptionHandler {

    /**
     * 异常处理方法
     * @return
     */
    @ExceptionHandler(CustomException.class)
    public Result exceptionHandler(CustomException ex) {
        log.error(ex.getMessage());
        return new Result(0,"发生异常",ex.getMessage());
    }
}
